
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 05/08/2011 16:13:14
-- Generated from EDMX file: F:\Documents\CS\毕业设计\毕业设计管理系统\GPMS.Model\GPMSDb.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [GPMS];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_SpecialtyUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserInfos] DROP CONSTRAINT [FK_SpecialtyUser];
GO
IF OBJECT_ID(N'[dbo].[FK_UserSendMessage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Messages] DROP CONSTRAINT [FK_UserSendMessage];
GO
IF OBJECT_ID(N'[dbo].[FK_UserReceiveMessage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Messages] DROP CONSTRAINT [FK_UserReceiveMessage];
GO
IF OBJECT_ID(N'[dbo].[FK_GPSelectionUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GPSelections] DROP CONSTRAINT [FK_GPSelectionUser];
GO
IF OBJECT_ID(N'[dbo].[FK_Guiding]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GraduationProjects] DROP CONSTRAINT [FK_Guiding];
GO
IF OBJECT_ID(N'[dbo].[FK_UserRole_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserRole] DROP CONSTRAINT [FK_UserRole_User];
GO
IF OBJECT_ID(N'[dbo].[FK_UserRole_Role]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserRole] DROP CONSTRAINT [FK_UserRole_Role];
GO
IF OBJECT_ID(N'[dbo].[FK_GPSelectionGraduationProject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GPSelections] DROP CONSTRAINT [FK_GPSelectionGraduationProject];
GO
IF OBJECT_ID(N'[dbo].[FK_ControllerInfoActionInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ActionInfos] DROP CONSTRAINT [FK_ControllerInfoActionInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_ActionInfoRole_ActionInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ActionInfoRole] DROP CONSTRAINT [FK_ActionInfoRole_ActionInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_ActionInfoRole_Role]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ActionInfoRole] DROP CONSTRAINT [FK_ActionInfoRole_Role];
GO
IF OBJECT_ID(N'[dbo].[FK_GuestBookItemUserInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GuestBookItems] DROP CONSTRAINT [FK_GuestBookItemUserInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_GuestBookItemUserInfo1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GuestBookItems] DROP CONSTRAINT [FK_GuestBookItemUserInfo1];
GO
IF OBJECT_ID(N'[dbo].[FK_LinkFile]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Links] DROP CONSTRAINT [FK_LinkFile];
GO
IF OBJECT_ID(N'[dbo].[FK_FileUserInfo_File]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FileUserInfo] DROP CONSTRAINT [FK_FileUserInfo_File];
GO
IF OBJECT_ID(N'[dbo].[FK_FileUserInfo_UserInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FileUserInfo] DROP CONSTRAINT [FK_FileUserInfo_UserInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_ActionInfoLink]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Links] DROP CONSTRAINT [FK_ActionInfoLink];
GO
IF OBJECT_ID(N'[dbo].[FK_SettingRole]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Settings] DROP CONSTRAINT [FK_SettingRole];
GO
IF OBJECT_ID(N'[dbo].[FK_SettingRole1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Settings] DROP CONSTRAINT [FK_SettingRole1];
GO
IF OBJECT_ID(N'[dbo].[FK_GPSelectionProjectPlan]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectPlans] DROP CONSTRAINT [FK_GPSelectionProjectPlan];
GO
IF OBJECT_ID(N'[dbo].[FK_AnswerGroupUserInfo1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AnswerGroups] DROP CONSTRAINT [FK_AnswerGroupUserInfo1];
GO
IF OBJECT_ID(N'[dbo].[FK_MessageFile_Message]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MessageFile] DROP CONSTRAINT [FK_MessageFile_Message];
GO
IF OBJECT_ID(N'[dbo].[FK_MessageFile_File]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MessageFile] DROP CONSTRAINT [FK_MessageFile_File];
GO
IF OBJECT_ID(N'[dbo].[FK_AnswerGroupStudent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserInfos] DROP CONSTRAINT [FK_AnswerGroupStudent];
GO
IF OBJECT_ID(N'[dbo].[FK_AnswerGroupTeachers_AnswerGroup]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AnswerGroupTeachers] DROP CONSTRAINT [FK_AnswerGroupTeachers_AnswerGroup];
GO
IF OBJECT_ID(N'[dbo].[FK_AnswerGroupTeachers_UserInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AnswerGroupTeachers] DROP CONSTRAINT [FK_AnswerGroupTeachers_UserInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_FileProjectPlan]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectPlans] DROP CONSTRAINT [FK_FileProjectPlan];
GO
IF OBJECT_ID(N'[dbo].[FK_UserInfoFile]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Files] DROP CONSTRAINT [FK_UserInfoFile];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Specialties]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Specialties];
GO
IF OBJECT_ID(N'[dbo].[GraduationProjects]', 'U') IS NOT NULL
    DROP TABLE [dbo].[GraduationProjects];
GO
IF OBJECT_ID(N'[dbo].[ProjectPlans]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectPlans];
GO
IF OBJECT_ID(N'[dbo].[UserInfos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserInfos];
GO
IF OBJECT_ID(N'[dbo].[GPSelections]', 'U') IS NOT NULL
    DROP TABLE [dbo].[GPSelections];
GO
IF OBJECT_ID(N'[dbo].[Messages]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Messages];
GO
IF OBJECT_ID(N'[dbo].[Roles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Roles];
GO
IF OBJECT_ID(N'[dbo].[ActionInfos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ActionInfos];
GO
IF OBJECT_ID(N'[dbo].[ControllerInfos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ControllerInfos];
GO
IF OBJECT_ID(N'[dbo].[Links]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Links];
GO
IF OBJECT_ID(N'[dbo].[Files]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Files];
GO
IF OBJECT_ID(N'[dbo].[GuestBookItems]', 'U') IS NOT NULL
    DROP TABLE [dbo].[GuestBookItems];
GO
IF OBJECT_ID(N'[dbo].[Settings]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Settings];
GO
IF OBJECT_ID(N'[dbo].[AnswerGroups]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AnswerGroups];
GO
IF OBJECT_ID(N'[dbo].[UserRole]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserRole];
GO
IF OBJECT_ID(N'[dbo].[ActionInfoRole]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ActionInfoRole];
GO
IF OBJECT_ID(N'[dbo].[FileUserInfo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FileUserInfo];
GO
IF OBJECT_ID(N'[dbo].[MessageFile]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MessageFile];
GO
IF OBJECT_ID(N'[dbo].[AnswerGroupTeachers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AnswerGroupTeachers];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Specialties'
CREATE TABLE [dbo].[Specialties] (
    [SpecialtyID] uniqueidentifier  NOT NULL,
    [SpecialtyName] nvarchar(max)  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [IsDeleted] bit  NOT NULL,
    [Description] nvarchar(max)  NULL
);
GO

-- Creating table 'GraduationProjects'
CREATE TABLE [dbo].[GraduationProjects] (
    [GPID] uniqueidentifier  NOT NULL,
    [GPName] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Type] nvarchar(max)  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [GuiderID] uniqueidentifier  NOT NULL,
    [Maxman] smallint  NOT NULL,
    [Audit] bit  NOT NULL,
    [Claim] nvarchar(max)  NULL
);
GO

-- Creating table 'ProjectPlans'
CREATE TABLE [dbo].[ProjectPlans] (
    [PlanID] uniqueidentifier  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [BeginDate] datetime  NOT NULL,
    [FinishDate] datetime  NOT NULL,
    [IsDone] bit  NOT NULL,
    [RealFinishDate] datetime  NULL,
    [SelectionID] uniqueidentifier  NOT NULL,
    [Mark] float  NULL,
    [Evaluation] nvarchar(max)  NULL,
    [FileID] uniqueidentifier  NULL
);
GO

-- Creating table 'UserInfos'
CREATE TABLE [dbo].[UserInfos] (
    [UserID] uniqueidentifier  NOT NULL,
    [UserName] nvarchar(max)  NOT NULL,
    [RealName] nvarchar(max)  NULL,
    [Sex] bit  NULL,
    [Birthday] datetime  NULL,
    [CreateDate] datetime  NOT NULL,
    [IsLocked] bit  NOT NULL,
    [IsDeleted] bit  NOT NULL,
    [Phone] nvarchar(max)  NULL,
    [IM] nvarchar(max)  NULL,
    [Password] nvarchar(max)  NOT NULL,
    [UserIdentity] nvarchar(max)  NULL,
    [SpecialtyID] uniqueidentifier  NOT NULL,
    [Email] nvarchar(max)  NULL,
    [Status] nvarchar(max)  NULL,
    [LeadeAnswerGroupID] uniqueidentifier  NULL,
    [AnswerGroup_AnswerGroupID] uniqueidentifier  NULL
);
GO

-- Creating table 'GPSelections'
CREATE TABLE [dbo].[GPSelections] (
    [SelectionID] uniqueidentifier  NOT NULL,
    [SelectDate] datetime  NOT NULL,
    [IsConfirm] bit  NOT NULL,
    [GPID] uniqueidentifier  NOT NULL,
    [UserID] uniqueidentifier  NOT NULL,
    [GuiderMark] float  NULL,
    [GuiderEvaluation] nvarchar(max)  NULL,
    [LeaderMark] float  NULL,
    [LeaderEvaluation] nvarchar(max)  NULL,
    [ReviewerMark] float  NULL,
    [ReviewerEvaluation] nvarchar(max)  NULL
);
GO

-- Creating table 'Messages'
CREATE TABLE [dbo].[Messages] (
    [MessageID] uniqueidentifier  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [Context] nvarchar(max)  NOT NULL,
    [IsRead] bit  NOT NULL,
    [IsDeletedSender] bit  NOT NULL,
    [SenderID] uniqueidentifier  NOT NULL,
    [ReceiverID] uniqueidentifier  NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [IsDeletedReceiver] bit  NOT NULL,
    [FileID] uniqueidentifier  NULL
);
GO

-- Creating table 'Roles'
CREATE TABLE [dbo].[Roles] (
    [RoleID] uniqueidentifier  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [RoleName] nvarchar(max)  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [IsDeleted] bit  NOT NULL,
    [Display] bit  NOT NULL,
    [IsMain] bit  NOT NULL,
    [IsDefault] bit  NOT NULL
);
GO

-- Creating table 'ActionInfos'
CREATE TABLE [dbo].[ActionInfos] (
    [ActionID] uniqueidentifier  NOT NULL,
    [ActionName] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [CreateDate] datetime  NOT NULL,
    [IsDeleted] bit  NOT NULL,
    [ControllerID] uniqueidentifier  NOT NULL,
    [ReturnType] nvarchar(max)  NULL
);
GO

-- Creating table 'ControllerInfos'
CREATE TABLE [dbo].[ControllerInfos] (
    [ControllerID] uniqueidentifier  NOT NULL,
    [ControllerName] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [CreateDate] datetime  NOT NULL,
    [IsDeleted] bit  NOT NULL
);
GO

-- Creating table 'Links'
CREATE TABLE [dbo].[Links] (
    [LinkID] uniqueidentifier  NOT NULL,
    [LinkName] nvarchar(max)  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [IsDeleted] bit  NOT NULL,
    [FileID] uniqueidentifier  NULL,
    [Width] int  NULL,
    [Height] int  NULL,
    [Maxable] bit  NOT NULL,
    [Minable] bit  NOT NULL,
    [ActionID] uniqueidentifier  NOT NULL,
    [LinkType] nvarchar(max)  NOT NULL,
    [Resizeable] bit  NOT NULL,
    [Fullscreen] bit  NOT NULL
);
GO

-- Creating table 'Files'
CREATE TABLE [dbo].[Files] (
    [FileID] uniqueidentifier  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Size] bigint  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [MimeType] nvarchar(max)  NOT NULL,
    [FileType] nvarchar(max)  NOT NULL,
    [UserInfoUserID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'GuestBookItems'
CREATE TABLE [dbo].[GuestBookItems] (
    [GuestBookItemID] uniqueidentifier  NOT NULL,
    [OwnerUserID] uniqueidentifier  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [IsDeleted] bit  NOT NULL,
    [Content] nvarchar(max)  NOT NULL,
    [VisitorUserID] uniqueidentifier  NOT NULL,
    [Reply] nvarchar(max)  NULL,
    [Title] nvarchar(max)  NOT NULL,
    [IsHide] bit  NOT NULL
);
GO

-- Creating table 'Settings'
CREATE TABLE [dbo].[Settings] (
    [ID] uniqueidentifier  NOT NULL,
    [MaxSelect] int  NOT NULL,
    [MaxPublish] int  NOT NULL,
    [PageSize] int  NOT NULL,
    [Announcement] nvarchar(max)  NULL,
    [IsClose] bit  NOT NULL,
    [TeacherRole] uniqueidentifier  NOT NULL,
    [StudentRole] uniqueidentifier  NOT NULL,
    [MaxAnswerStudent] int  NOT NULL,
    [MaxAnswerTeacher] int  NOT NULL
);
GO

-- Creating table 'AnswerGroups'
CREATE TABLE [dbo].[AnswerGroups] (
    [AnswerGroupID] uniqueidentifier  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [Place] nvarchar(max)  NOT NULL,
    [Date] datetime  NOT NULL,
    [LeaderID] uniqueidentifier  NOT NULL,
    [BeginTime] nvarchar(max)  NOT NULL,
    [EndTime] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'UserRole'
CREATE TABLE [dbo].[UserRole] (
    [Users_UserID] uniqueidentifier  NOT NULL,
    [Roles_RoleID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'ActionInfoRole'
CREATE TABLE [dbo].[ActionInfoRole] (
    [ActionInfos_ActionID] uniqueidentifier  NOT NULL,
    [Roles_RoleID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'FileUserInfo'
CREATE TABLE [dbo].[FileUserInfo] (
    [AccessFiles_FileID] uniqueidentifier  NOT NULL,
    [AccessUsers_UserID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'AnswerGroupTeachers'
CREATE TABLE [dbo].[AnswerGroupTeachers] (
    [AnswerGroupsForTeacher_AnswerGroupID] uniqueidentifier  NOT NULL,
    [Teachers_UserID] uniqueidentifier  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [SpecialtyID] in table 'Specialties'
ALTER TABLE [dbo].[Specialties]
ADD CONSTRAINT [PK_Specialties]
    PRIMARY KEY CLUSTERED ([SpecialtyID] ASC);
GO

-- Creating primary key on [GPID] in table 'GraduationProjects'
ALTER TABLE [dbo].[GraduationProjects]
ADD CONSTRAINT [PK_GraduationProjects]
    PRIMARY KEY CLUSTERED ([GPID] ASC);
GO

-- Creating primary key on [PlanID] in table 'ProjectPlans'
ALTER TABLE [dbo].[ProjectPlans]
ADD CONSTRAINT [PK_ProjectPlans]
    PRIMARY KEY CLUSTERED ([PlanID] ASC);
GO

-- Creating primary key on [UserID] in table 'UserInfos'
ALTER TABLE [dbo].[UserInfos]
ADD CONSTRAINT [PK_UserInfos]
    PRIMARY KEY CLUSTERED ([UserID] ASC);
GO

-- Creating primary key on [SelectionID] in table 'GPSelections'
ALTER TABLE [dbo].[GPSelections]
ADD CONSTRAINT [PK_GPSelections]
    PRIMARY KEY CLUSTERED ([SelectionID] ASC);
GO

-- Creating primary key on [MessageID] in table 'Messages'
ALTER TABLE [dbo].[Messages]
ADD CONSTRAINT [PK_Messages]
    PRIMARY KEY CLUSTERED ([MessageID] ASC);
GO

-- Creating primary key on [RoleID] in table 'Roles'
ALTER TABLE [dbo].[Roles]
ADD CONSTRAINT [PK_Roles]
    PRIMARY KEY CLUSTERED ([RoleID] ASC);
GO

-- Creating primary key on [ActionID] in table 'ActionInfos'
ALTER TABLE [dbo].[ActionInfos]
ADD CONSTRAINT [PK_ActionInfos]
    PRIMARY KEY CLUSTERED ([ActionID] ASC);
GO

-- Creating primary key on [ControllerID] in table 'ControllerInfos'
ALTER TABLE [dbo].[ControllerInfos]
ADD CONSTRAINT [PK_ControllerInfos]
    PRIMARY KEY CLUSTERED ([ControllerID] ASC);
GO

-- Creating primary key on [LinkID] in table 'Links'
ALTER TABLE [dbo].[Links]
ADD CONSTRAINT [PK_Links]
    PRIMARY KEY CLUSTERED ([LinkID] ASC);
GO

-- Creating primary key on [FileID] in table 'Files'
ALTER TABLE [dbo].[Files]
ADD CONSTRAINT [PK_Files]
    PRIMARY KEY CLUSTERED ([FileID] ASC);
GO

-- Creating primary key on [GuestBookItemID] in table 'GuestBookItems'
ALTER TABLE [dbo].[GuestBookItems]
ADD CONSTRAINT [PK_GuestBookItems]
    PRIMARY KEY CLUSTERED ([GuestBookItemID] ASC);
GO

-- Creating primary key on [ID] in table 'Settings'
ALTER TABLE [dbo].[Settings]
ADD CONSTRAINT [PK_Settings]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [AnswerGroupID] in table 'AnswerGroups'
ALTER TABLE [dbo].[AnswerGroups]
ADD CONSTRAINT [PK_AnswerGroups]
    PRIMARY KEY CLUSTERED ([AnswerGroupID] ASC);
GO

-- Creating primary key on [Users_UserID], [Roles_RoleID] in table 'UserRole'
ALTER TABLE [dbo].[UserRole]
ADD CONSTRAINT [PK_UserRole]
    PRIMARY KEY NONCLUSTERED ([Users_UserID], [Roles_RoleID] ASC);
GO

-- Creating primary key on [ActionInfos_ActionID], [Roles_RoleID] in table 'ActionInfoRole'
ALTER TABLE [dbo].[ActionInfoRole]
ADD CONSTRAINT [PK_ActionInfoRole]
    PRIMARY KEY NONCLUSTERED ([ActionInfos_ActionID], [Roles_RoleID] ASC);
GO

-- Creating primary key on [AccessFiles_FileID], [AccessUsers_UserID] in table 'FileUserInfo'
ALTER TABLE [dbo].[FileUserInfo]
ADD CONSTRAINT [PK_FileUserInfo]
    PRIMARY KEY NONCLUSTERED ([AccessFiles_FileID], [AccessUsers_UserID] ASC);
GO

-- Creating primary key on [AnswerGroupsForTeacher_AnswerGroupID], [Teachers_UserID] in table 'AnswerGroupTeachers'
ALTER TABLE [dbo].[AnswerGroupTeachers]
ADD CONSTRAINT [PK_AnswerGroupTeachers]
    PRIMARY KEY NONCLUSTERED ([AnswerGroupsForTeacher_AnswerGroupID], [Teachers_UserID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [SpecialtyID] in table 'UserInfos'
ALTER TABLE [dbo].[UserInfos]
ADD CONSTRAINT [FK_SpecialtyUser]
    FOREIGN KEY ([SpecialtyID])
    REFERENCES [dbo].[Specialties]
        ([SpecialtyID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SpecialtyUser'
CREATE INDEX [IX_FK_SpecialtyUser]
ON [dbo].[UserInfos]
    ([SpecialtyID]);
GO

-- Creating foreign key on [SenderID] in table 'Messages'
ALTER TABLE [dbo].[Messages]
ADD CONSTRAINT [FK_UserSendMessage]
    FOREIGN KEY ([SenderID])
    REFERENCES [dbo].[UserInfos]
        ([UserID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserSendMessage'
CREATE INDEX [IX_FK_UserSendMessage]
ON [dbo].[Messages]
    ([SenderID]);
GO

-- Creating foreign key on [ReceiverID] in table 'Messages'
ALTER TABLE [dbo].[Messages]
ADD CONSTRAINT [FK_UserReceiveMessage]
    FOREIGN KEY ([ReceiverID])
    REFERENCES [dbo].[UserInfos]
        ([UserID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserReceiveMessage'
CREATE INDEX [IX_FK_UserReceiveMessage]
ON [dbo].[Messages]
    ([ReceiverID]);
GO

-- Creating foreign key on [UserID] in table 'GPSelections'
ALTER TABLE [dbo].[GPSelections]
ADD CONSTRAINT [FK_GPSelectionUser]
    FOREIGN KEY ([UserID])
    REFERENCES [dbo].[UserInfos]
        ([UserID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GPSelectionUser'
CREATE INDEX [IX_FK_GPSelectionUser]
ON [dbo].[GPSelections]
    ([UserID]);
GO

-- Creating foreign key on [GuiderID] in table 'GraduationProjects'
ALTER TABLE [dbo].[GraduationProjects]
ADD CONSTRAINT [FK_Guiding]
    FOREIGN KEY ([GuiderID])
    REFERENCES [dbo].[UserInfos]
        ([UserID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Guiding'
CREATE INDEX [IX_FK_Guiding]
ON [dbo].[GraduationProjects]
    ([GuiderID]);
GO

-- Creating foreign key on [Users_UserID] in table 'UserRole'
ALTER TABLE [dbo].[UserRole]
ADD CONSTRAINT [FK_UserRole_User]
    FOREIGN KEY ([Users_UserID])
    REFERENCES [dbo].[UserInfos]
        ([UserID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Roles_RoleID] in table 'UserRole'
ALTER TABLE [dbo].[UserRole]
ADD CONSTRAINT [FK_UserRole_Role]
    FOREIGN KEY ([Roles_RoleID])
    REFERENCES [dbo].[Roles]
        ([RoleID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserRole_Role'
CREATE INDEX [IX_FK_UserRole_Role]
ON [dbo].[UserRole]
    ([Roles_RoleID]);
GO

-- Creating foreign key on [GPID] in table 'GPSelections'
ALTER TABLE [dbo].[GPSelections]
ADD CONSTRAINT [FK_GPSelectionGraduationProject]
    FOREIGN KEY ([GPID])
    REFERENCES [dbo].[GraduationProjects]
        ([GPID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GPSelectionGraduationProject'
CREATE INDEX [IX_FK_GPSelectionGraduationProject]
ON [dbo].[GPSelections]
    ([GPID]);
GO

-- Creating foreign key on [ControllerID] in table 'ActionInfos'
ALTER TABLE [dbo].[ActionInfos]
ADD CONSTRAINT [FK_ControllerInfoActionInfo]
    FOREIGN KEY ([ControllerID])
    REFERENCES [dbo].[ControllerInfos]
        ([ControllerID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ControllerInfoActionInfo'
CREATE INDEX [IX_FK_ControllerInfoActionInfo]
ON [dbo].[ActionInfos]
    ([ControllerID]);
GO

-- Creating foreign key on [ActionInfos_ActionID] in table 'ActionInfoRole'
ALTER TABLE [dbo].[ActionInfoRole]
ADD CONSTRAINT [FK_ActionInfoRole_ActionInfo]
    FOREIGN KEY ([ActionInfos_ActionID])
    REFERENCES [dbo].[ActionInfos]
        ([ActionID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Roles_RoleID] in table 'ActionInfoRole'
ALTER TABLE [dbo].[ActionInfoRole]
ADD CONSTRAINT [FK_ActionInfoRole_Role]
    FOREIGN KEY ([Roles_RoleID])
    REFERENCES [dbo].[Roles]
        ([RoleID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ActionInfoRole_Role'
CREATE INDEX [IX_FK_ActionInfoRole_Role]
ON [dbo].[ActionInfoRole]
    ([Roles_RoleID]);
GO

-- Creating foreign key on [OwnerUserID] in table 'GuestBookItems'
ALTER TABLE [dbo].[GuestBookItems]
ADD CONSTRAINT [FK_GuestBookItemUserInfo]
    FOREIGN KEY ([OwnerUserID])
    REFERENCES [dbo].[UserInfos]
        ([UserID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GuestBookItemUserInfo'
CREATE INDEX [IX_FK_GuestBookItemUserInfo]
ON [dbo].[GuestBookItems]
    ([OwnerUserID]);
GO

-- Creating foreign key on [VisitorUserID] in table 'GuestBookItems'
ALTER TABLE [dbo].[GuestBookItems]
ADD CONSTRAINT [FK_GuestBookItemUserInfo1]
    FOREIGN KEY ([VisitorUserID])
    REFERENCES [dbo].[UserInfos]
        ([UserID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GuestBookItemUserInfo1'
CREATE INDEX [IX_FK_GuestBookItemUserInfo1]
ON [dbo].[GuestBookItems]
    ([VisitorUserID]);
GO

-- Creating foreign key on [FileID] in table 'Links'
ALTER TABLE [dbo].[Links]
ADD CONSTRAINT [FK_LinkFile]
    FOREIGN KEY ([FileID])
    REFERENCES [dbo].[Files]
        ([FileID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LinkFile'
CREATE INDEX [IX_FK_LinkFile]
ON [dbo].[Links]
    ([FileID]);
GO

-- Creating foreign key on [AccessFiles_FileID] in table 'FileUserInfo'
ALTER TABLE [dbo].[FileUserInfo]
ADD CONSTRAINT [FK_FileUserInfo_File]
    FOREIGN KEY ([AccessFiles_FileID])
    REFERENCES [dbo].[Files]
        ([FileID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [AccessUsers_UserID] in table 'FileUserInfo'
ALTER TABLE [dbo].[FileUserInfo]
ADD CONSTRAINT [FK_FileUserInfo_UserInfo]
    FOREIGN KEY ([AccessUsers_UserID])
    REFERENCES [dbo].[UserInfos]
        ([UserID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FileUserInfo_UserInfo'
CREATE INDEX [IX_FK_FileUserInfo_UserInfo]
ON [dbo].[FileUserInfo]
    ([AccessUsers_UserID]);
GO

-- Creating foreign key on [ActionID] in table 'Links'
ALTER TABLE [dbo].[Links]
ADD CONSTRAINT [FK_ActionInfoLink]
    FOREIGN KEY ([ActionID])
    REFERENCES [dbo].[ActionInfos]
        ([ActionID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ActionInfoLink'
CREATE INDEX [IX_FK_ActionInfoLink]
ON [dbo].[Links]
    ([ActionID]);
GO

-- Creating foreign key on [TeacherRole] in table 'Settings'
ALTER TABLE [dbo].[Settings]
ADD CONSTRAINT [FK_SettingRole]
    FOREIGN KEY ([TeacherRole])
    REFERENCES [dbo].[Roles]
        ([RoleID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SettingRole'
CREATE INDEX [IX_FK_SettingRole]
ON [dbo].[Settings]
    ([TeacherRole]);
GO

-- Creating foreign key on [StudentRole] in table 'Settings'
ALTER TABLE [dbo].[Settings]
ADD CONSTRAINT [FK_SettingRole1]
    FOREIGN KEY ([StudentRole])
    REFERENCES [dbo].[Roles]
        ([RoleID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SettingRole1'
CREATE INDEX [IX_FK_SettingRole1]
ON [dbo].[Settings]
    ([StudentRole]);
GO

-- Creating foreign key on [SelectionID] in table 'ProjectPlans'
ALTER TABLE [dbo].[ProjectPlans]
ADD CONSTRAINT [FK_GPSelectionProjectPlan]
    FOREIGN KEY ([SelectionID])
    REFERENCES [dbo].[GPSelections]
        ([SelectionID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GPSelectionProjectPlan'
CREATE INDEX [IX_FK_GPSelectionProjectPlan]
ON [dbo].[ProjectPlans]
    ([SelectionID]);
GO

-- Creating foreign key on [LeaderID] in table 'AnswerGroups'
ALTER TABLE [dbo].[AnswerGroups]
ADD CONSTRAINT [FK_AnswerGroupUserInfo1]
    FOREIGN KEY ([LeaderID])
    REFERENCES [dbo].[UserInfos]
        ([UserID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AnswerGroupUserInfo1'
CREATE INDEX [IX_FK_AnswerGroupUserInfo1]
ON [dbo].[AnswerGroups]
    ([LeaderID]);
GO

-- Creating foreign key on [FileID] in table 'Messages'
ALTER TABLE [dbo].[Messages]
ADD CONSTRAINT [FK_MessageFile]
    FOREIGN KEY ([FileID])
    REFERENCES [dbo].[Files]
        ([FileID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MessageFile'
CREATE INDEX [IX_FK_MessageFile]
ON [dbo].[Messages]
    ([FileID]);
GO

-- Creating foreign key on [AnswerGroup_AnswerGroupID] in table 'UserInfos'
ALTER TABLE [dbo].[UserInfos]
ADD CONSTRAINT [FK_AnswerGroupStudent]
    FOREIGN KEY ([AnswerGroup_AnswerGroupID])
    REFERENCES [dbo].[AnswerGroups]
        ([AnswerGroupID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AnswerGroupStudent'
CREATE INDEX [IX_FK_AnswerGroupStudent]
ON [dbo].[UserInfos]
    ([AnswerGroup_AnswerGroupID]);
GO

-- Creating foreign key on [AnswerGroupsForTeacher_AnswerGroupID] in table 'AnswerGroupTeachers'
ALTER TABLE [dbo].[AnswerGroupTeachers]
ADD CONSTRAINT [FK_AnswerGroupTeachers_AnswerGroup]
    FOREIGN KEY ([AnswerGroupsForTeacher_AnswerGroupID])
    REFERENCES [dbo].[AnswerGroups]
        ([AnswerGroupID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Teachers_UserID] in table 'AnswerGroupTeachers'
ALTER TABLE [dbo].[AnswerGroupTeachers]
ADD CONSTRAINT [FK_AnswerGroupTeachers_UserInfo]
    FOREIGN KEY ([Teachers_UserID])
    REFERENCES [dbo].[UserInfos]
        ([UserID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AnswerGroupTeachers_UserInfo'
CREATE INDEX [IX_FK_AnswerGroupTeachers_UserInfo]
ON [dbo].[AnswerGroupTeachers]
    ([Teachers_UserID]);
GO

-- Creating foreign key on [FileID] in table 'ProjectPlans'
ALTER TABLE [dbo].[ProjectPlans]
ADD CONSTRAINT [FK_FileProjectPlan]
    FOREIGN KEY ([FileID])
    REFERENCES [dbo].[Files]
        ([FileID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FileProjectPlan'
CREATE INDEX [IX_FK_FileProjectPlan]
ON [dbo].[ProjectPlans]
    ([FileID]);
GO

-- Creating foreign key on [UserInfoUserID] in table 'Files'
ALTER TABLE [dbo].[Files]
ADD CONSTRAINT [FK_UserInfoFile]
    FOREIGN KEY ([UserInfoUserID])
    REFERENCES [dbo].[UserInfos]
        ([UserID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserInfoFile'
CREATE INDEX [IX_FK_UserInfoFile]
ON [dbo].[Files]
    ([UserInfoUserID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------